<?php
namespace app\admin\controller;
use think\Db;
use think\Controller;
use think\Request;
use think\Session;
use think\db\Connection;
class Type extends Controller{
    //    商品类型属性添加
    public function type()
    {
        return view("type");
    }

//    商品类型属性添加操作
    public function type1()
    {
        $request = Request::instance();
        $type_name = $request->post('type_name');
        $res = Db::execute("insert into man_type values ('','$type_name')");
        if ($res) {
            return $this->type_show();
        }
    }

//商品类型属性显示
    public function type_show()
    {
        $tdata = Db::query("select * from man_type");
        return view("type_show", ['tdata' => $tdata]);
    }

//商品属性列表
    public function type_attr()
    {
        $type_id = input('get.type_id');
        $sql = "select * from man_attr,man_type where man_attr.type_id=man_type.type_id and man_attr.type_id=$type_id";
        $adata = Db::query($sql);
        return view("type_attr", ['adata' => $adata]);
    }
//商品属性添}加
    public function attr_add()
    {
        $sql = "select * from man_type";
        $tdata = Db::query($sql);
        return view("attr_add", ['tdata' => $tdata]);
    }
//商品属性添加操作
    public function attr_add_do()
    {
        $data = input('post.');
        $sql = "insert into man_attr values(null,'$data[a_name]',null,'$data[type_id]')";
        $res = Db::execute($sql);
        if($res){
            return $this->type_show();
        }else{
            return  $this->attr_add();
        }
    }

}